#!/bin/bash

source config/init_proj.sh

function changeProject()
{
    if [ ! -e Project/$1 ];then
        echo "project is not existing"
        return
    fi
    sed -i "s/\"project\".*/\"project\" : \"$1\"},/" .vscode/c_cpp_properties.json
    sed -i "s/PROJECT=.*/PROJECT=$1/" proj_config
}

if [ $# -lt 1 ];then
    echo "please input project name"
    exit 1
fi

if [ $1 = "-x" ];then
    changeProject $2
    exit 0
fi

if [ $1 = "-n" ];then
    cp -r Project/Template Project/$2
    changeProject $2
fi

if [ $1 = '-a' ];then
    if [ "$2"x = 'off'x ];then
        git update-index --assume-unchanged .vscode/c_cpp_properties.json
        git update-index --assume-unchanged .vscode/launch.json
    elif [ "$2"x = 'on'x ];then
        git update-index --no-assume-unchanged .vscode/c_cpp_properties.json
        git update-index --no-assume-unchanged .vscode/launch.json
    fi
fi